require(ggplot2)
require(scales)

## ITANES
require(memisc)
# Download from http://www.itanes.org/
itanes_2013 <- as.data.frame(as.data.set(spss.system.file("ITA2013_(envers2015_01_19).sav"))) # Not provided

itanes_voted_m5s_2013 <- subset(itanes_2013, d89=='M5S - Five Stars Movement (leader: Grillo)')
itanes_voted_m5s_2013_perc <- nrow(subset(itanes_2013, d89=='M5S - Five Stars Movement (leader: Grillo)')) /
  nrow(subset(itanes_2013, d89!='No Answer' & d89!='Blank/invalid ballot'))

m5s_rile_collocation <- as.data.frame(table(itanes_voted_m5s_2013$d39))
m5s_rile_collocation$voted_m5s <- "Voted M5S in 2013"
m5s_rile_collocation$perc <- m5s_rile_collocation$Freq / sum(m5s_rile_collocation$Freq)

all_rile_collocation <- as.data.frame(table(itanes_2013$d39))
all_rile_collocation$voted_m5s <- "All sample"
all_rile_collocation$perc <- all_rile_collocation$Freq / sum(all_rile_collocation$Freq)

print(ggplot(data=rbind(m5s_rile_collocation, all_rile_collocation), aes(x=Var1, y=perc, fill=voted_m5s)) + 
  geom_bar(position = 'dodge', stat='identity') +
  geom_text(aes(label=round(perc*100,digits=2)), position=position_dodge(width=0.9), vjust=-0.25, size=3)  +
  scale_y_continuous(breaks=c(0,0.25,0.50,0.75), labels=scales::percent) +
  labs(y=NULL,x=(paste0('(n=',nrow(itanes_2013),')'))) +
  guides(fill=guide_legend(title=NULL)) +
  theme(legend.position="bottom"))